<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="structures.User;"%>
<%User user = (User) session.getAttribute("user");%>
<%	String error = (String) session.getAttribute("error");
	session.removeAttribute("error");%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>TiVendoIo - Insert Ad</title>

    <!-- Bootstrap -->
    <link href="/serviceTechnologies/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/serviceTechnologies/bootstrap/css/select2-bootstrap.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" rel="stylesheet">
    <link href="css/style.css" rel = "stylesheet">
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script type="text/javascript">
	$(document).ready(function(){
		$('#footer').load('/serviceTechnologies/common/footer.jsp');
		$('#navbar').load('/serviceTechnologies/common/navbar.jsp');
	});
	</script>
	
	<script>
		$(document)
			.on('change', '.btn-file :file', function() {
				var input = $(this),
				numFiles = input.get(0).files ? input.get(0).files.length : 1,
				label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
				input.trigger('fileselect', [numFiles, label]);
		});
		
		$(document).ready( function() {
			$('.btn-file :file').on('fileselect', function(event, numFiles, label) {
				
				var input = $(this).parents('.input-group').find(':text'),
					log = numFiles > 1 ? numFiles + ' files selected' : label;
				
				if( input.length ) {
					input.val(log);
				} else {
					if( log ) alert(log);
				}
				
			});
		});		
	</script>
	

  </head>
  <body>
 	<div id="navbar"></div>
 	
   <div class="container">
  
	
   		<h3 align = "center">Insert a new Ad</h3>
   		
   		<div class="row omb_row-sm-offset-3 omb_loginOr">
			<div class="col-xs-12 col-sm-6">
				<hr class="omb_hrOr">
			</div>
		</div>
   		
   		<% if(user.getPayPalEmail()==null || user.getPayPalEmail().equals("null")) {%>
   			<h2>No PayPalEmail has been already inserted! Go to <a href="./profile.jsp">your personal page</a> to set it!</h2>
   		<%}else{ %>
   		<div class = "row omb_row-sm-offset-3">
   			<div class = "col-xs-12 col-sm-6">
   			<form action="./insertNewAd" autocomplete="off" method="POST" enctype="multipart/form-data">
   				<div class="input-group">
						<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
						<input type="text" class="form-control" name="title" placeholder="Title">
				</div>
				<span class="help-block"></span>
				
   				<div class="input-group">
						<span class="input-group-addon"><i class="fa fa-chevron-right"></i></span>
						<textarea class="form-control" rows="3" name="description" placeholder="Description" style="resize:none"></textarea>
				</div>
				<span class="help-block"></span>
				
				<div class="input-group">
						<span class="input-group-addon"><i class="fa fa-euro"></i></span>
						<input type="text" class="form-control" name="price" placeholder="Price (XX.XX)">
				</div>
				<span class="help-block"></span>
				
				<div class="input-group">
					<span class="input-group-btn">
						<span class="btn btn-primary btn-file">
							Browse <input type="file" multiple name="photo">
						</span>
					</span>
					<input type="text" class="form-control" readonly>
				</div><span class="help-block"></span>
				<input type="hidden" name="idUser" placeholder="idUser" value = "<%=user.getId()%>">
				<input type="hidden" name="payPalEmail" placeholder="payPalEmail" value = "<%=user.getPayPalEmail()%>">
				<button class="btn btn-lg btn-primary btn-block" type="submit">Insert</button>
			</form>
   			</div>
   		</div>
		
		<%} %>
		
	
    </div> <!-- End Container -->
 	
 	<div id="footer"></div>
 	<!-- End footer -->
 	
 	<% if(error!=null){
 			if(error.equals("yes")){%>
 				<script type="text/javascript">alert("Error while inserting the AD")</script>
 			<%}
 		} %>
 	
  </body>
 </html>